package member

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
	"woo-server/controllers"
	"woo-server/services/member"
)

func UserConfig(c *gin.Context) {
	// common
	com := controllers.NewCommon(c, "GetUserConfig")

	// 生成service
	Service := member.NewMemberService(com)
	result := Service.GetUserConfig()

	// 返回
	c.JSON(http.StatusOK, result)
}

// @tags 后台角色列表
// @summary 后台角色管理
// @Description 后台角色列表
// @Accept json
// @Success 200 {string} json "{"StatusCode":200,"Data":""}"
// @Router /Menu/List [get]
func UserList(c *gin.Context) {
	// common
	com := controllers.NewCommon(c, "GetUserList")

	// 生成登录态
	Service := member.NewMemberService(com)
	result := Service.GetList(c)

	// 返回
	c.JSON(http.StatusOK, result)
}

// @tags 后台角色
// @summary 后台角色配置
// @Description 后台角色管理列表配置项
// @Accept json
// @Success 200 {string} json "{"StatusCode":200,"Data":""}"
// @Router //Save [get]
func UserStatus(c *gin.Context) {
	// common
	com := controllers.NewCommon(c, "PostSave")

	// 生成service
	Service := member.NewMemberService(com)
	result := Service.PostSave(c)

	// 返回
	c.JSON(http.StatusOK, result)
}

// @tags 后台角色
// @summary 删除角色
// @Description 后台角色管理--删除角色
// @Accept json
// @Success 200 {string} json "{"StatusCode":200,"Data":""}"
// @Router //Save [get]
func UserDelete(c *gin.Context) {
	// common
	com := controllers.NewCommon(c, "PostSave")

	// 生成service
	Service := member.NewMemberService(com)
	result := Service.Delete(c)

	// 返回
	c.JSON(http.StatusOK, result)
}

func SendMail(c *gin.Context) {
	//定义收件人
	mailTo := []string{
		"colinwoo@colinwoo.com",
	}
	//邮件主题为"Hello"
	subject := "Hello by golang gomail from exmail.qq.com"
	// 邮件正文
	body := "Hello,by gomail sent"
	// common
	com := controllers.NewCommon(c, "PostSave")

	// 生成service
	Service := member.NewMemberService(com)
	err := Service.SendMail(mailTo, subject, body)
	if err != nil {
		log.Println(err)
		fmt.Println("send fail")
		return
	}

	fmt.Println("send successfully")
}
